package com.example.SpringBootDemo.controller;

import com.example.SpringBootDemo.model.MessageInfo;
import com.example.SpringBootDemo.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/message")
@RestController
@Slf4j
public class MessgeController {
    @Autowired
    MessageService messageService;
    @RequestMapping("/setMessage")
    public boolean setMessege(MessageInfo messageInfo) {
        log.info("请求到达");
        // 判断是否有传过来的值为空
        if(!StringUtils.hasLength(messageInfo.getFrom()) ||
                !StringUtils.hasLength(messageInfo.getTo()) ||
                !StringUtils.hasLength(messageInfo.getMessage())) {
            return false;
        }
        messageService.addMessage(messageInfo);
        return true;
    }
    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageService.getMessage();
    }
}
